//
//  HMMainViewController.swift
//  SinaWeibo
//
//  Created by 统杰李 on 16/7/19.
//  Copyright © 2016年 统杰李. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //定义一个闭包
        let composeButtonClickClosure = {
            
            print("加号按钮点击了")
            
        }
        
        
        let tabBar = HMTabBar()
        //    self.tabBar = tabBar
        self.setValue(tabBar, forKey: "tabBar")
        
        tabBar.composeButtonClickClosure = composeButtonClickClosure

     addChildViewController(HMHomeViewController(), title: "首页", imgName: "tabbar_home")
        
        addChildViewController(HMMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        
        addChildViewController(HMDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        
        addChildViewController(HMProfileViewController(), title: "我", imgName: "tabbar_profile")
        
    }
    
    func addChildViewController(vc: UIViewController, title: String, imgName: String) {
        
        //设置title
        vc.title = title
        //设置图片
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
        
        
    }

}